using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.IO;
using Infragistics.WebUI.UltraWebChart;
using Infragistics.WebUI.UltraWebGauge;
using Infragistics.WebUI.UltraWebGrid;


public partial class Default2 : System.Web.UI.Page
{
    HtmlForm frmObj;
    int rowcount = 0;
    int colcount = 0;
    int itemcount = 0;
    string strPagesetRowID = "";
    string strErrorMessage = "";
    DataSet dsConfig = new DataSet();
    DataSet dsePageInfo = new DataSet();
    DataSet dseInputInfo = new DataSet();
    DataSet dseInput = new DataSet();
    DataRow drPageInfo = null;
    protected void Page_PreInit(object sender, EventArgs e)
    {
        this.Theme = Session["Theme"].ToString();
        this.Title = "MaxBlox";

    }

    protected void Page_Load(object sender, EventArgs e)
    {
        security hdds = new security();

        if (Session["userid"] == null) Response.Redirect(hdds.SessionExpiryURL);
        if (Session["userid"].ToString() == "") Response.Redirect(hdds.SessionExpiryURL);
        if (Request.QueryString["mn"] != null)
            hdds.logMenuClick(Request.QueryString["mn"].ToString());

        //Code added by Sampath on 18-Nov-2011 for IPP Vertical privilege
        if (Request.QueryString["mn"] != null)
        {
            if (!hdds.checkObjectMenuAccess(Request.QueryString["mn"]))
            {
                showmessage();
                return;
            }
        }

        //Code added by Sampath on 15-Nov-2011 for IPP Vertical privilege
        if (Request.QueryString["PK"] != null && Request.QueryString["pgs_id"] != null)
        {
            if (!hdds.checkRecordAccess(Request.QueryString["PK"].ToString(), Request.QueryString["pgs_id"].ToString()))
            {
                showmessage();
                return;
            }
        }

        HDDatabase HDD = new HDDatabase(); // Added by 'Imran Gani' on 24-Jul-2014, to collapse the Nav Bar for Dashboard
        DataRow drNav = HDD.GetTableRow("select * from sy_acr_mem where acr_id = '482d6b5b0ed4502e' and af_row_id = '5b6e730d7a6bd91a' and mem_value3 = 'false';");
        if (drNav != null)
        {
            Panel pnl = (Panel)this.Master.FindControl("panel1");
            if (pnl != null)
                pnl.Visible = false;
        }
        HDD = null;

        if (this.Master.FindControl("Form1") != null)
        {
            frmObj = (HtmlForm)this.Master.FindControl("Form1");
            if (!Page.IsPostBack)
            {
                if (Request.QueryString["default"] == null)
                {
                    string url = hdds.GetDashboardNavigateURL(Request.QueryString["mn"], Request.QueryString["pgs_id"]);
                    //Response.Redirect(url);
                }
            }

            if (Request.QueryString["pgs_id"] != null)
            {
                strPagesetRowID = Request.QueryString["pgs_id"].ToString();
            }

            GetConfigDataSet();

            PageInfoLoad PIL = new PageInfoLoad();
            dsePageInfo = PIL.GetPageSetPageCtrlInfo(strPagesetRowID); //dashboard_master
            drPageInfo = dsePageInfo.Tables["Page"].Rows[0];
            DataSet dsPageInfo1 = PIL.GetPageSetPageCtrlInfo("3c957a8204bfd624");//dashboard_detail
            dsePageInfo.Tables["Page"].Merge(dsPageInfo1.Tables["Page"]);
            //dsPageInfo.Tables["Page"].Merge(dsPageInfo2.Tables["Page"]);
            dsePageInfo.Tables["PageCtrl"].Merge(dsPageInfo1.Tables["PageCtrl"]);
            //dsPageInfo.Tables["PageCtrl"].Merge(dsPageInfo2.Tables["PageCtrl"]);
            dsePageInfo.Tables["PageKeys"].Merge(dsPageInfo1.Tables["PageKeys"]);
            //dsPageInfo.Tables["PageKeys"].Merge(dsPageInfo2.Tables["PageKeys"]);
            PIL = null;

            if (!Page.IsPostBack)
            {
                LoadLayoutStyle();
                LoadAvailableDashboards(lstAvailableDashboards);
                SetDefaultCount();
                rowcount = Convert.ToInt32(hfRowCount.Value);
                colcount = Convert.ToInt32(hfColumnCount.Value);
            }

            itemcount = lstSelectedDashboards.Items.Count;
            colcount = Convert.ToInt32(ddlLayoutStyle.SelectedValue);

            rowcount = GetRowCount(itemcount, colcount);

            CheckEditOperation();
            isViewMode();
            string strPK = "";
            if (Request.QueryString["PK"] != null)
            {
                strPK = Request.QueryString["PK"].ToString();
            }

            imgowner.Attributes.Add("onclick", "javascript:openlookupwindow('hfowner','txt_Owner','f496930dfe0b690f','" + strPK + "','" + HttpContext.Current.Request.QueryString["pgs_id"].ToString() + "');");

            if (Page.IsPostBack)
            {
                checkforButtonClick();
            }

            if (hdds.GetDefaultDashboard().Trim() != "")
            {
                ShowGoToListPageLink();
            }

            if (!Page.IsPostBack)
            {
                if (Request.QueryString["PK"] == null || Request.QueryString["CPY"] != null)
                {
                    txt_Owner.Text = Session["userid"].ToString();
                    hfowner.Value = Session["user_afrowid"].ToString();
                    if (Request.QueryString["CPY"] == null)
                    {
                        ChkActive.Checked = true;
                    }
                }
            }

            setHeaderText();
        }
        
    }


    private void showmessage()
    {
        try
        {
            lblmessage.Text = wrapItAsMessage("<img src=\"Images/info.gif\" alt=\"\"></img>&nbsp;You do not have sufficient access permission.", true);
            pnlButtons.Visible = false;
            pnlButtonsTop.Visible = false;
            pnlHeader.Visible = false;
            pnlSelectDashboards.Visible = false;
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("showmessage: Error: " + ex.Message);
        }
    }

    private void SetDefaultCount()
    {
        if (!Page.IsPostBack)
        {
            hfRowCount.Value = "1";
            hfColumnCount.Value = ddlLayoutStyle.SelectedValue;
        }
    }

    private void CreateHTMLTable(ref HtmlTableCell htcResult,int rowcount,int colcount)
    {
        HtmlTable ht = new HtmlTable();
        HtmlTableRow htr = new HtmlTableRow();
        HtmlTableCell htc = new HtmlTableCell();
        try
        {
            ht = new HtmlTable();
            ht.Width = "100%";
            ht.CellPadding = 0;
            ht.CellSpacing = 0;
            ht.Border = 0;
            for (int i = 0; i < rowcount; i++)
            {
                htr = new HtmlTableRow();
                for (int j = 0; j < colcount; j++)
                {
                    htc = new HtmlTableCell();

                    string position = i + "," + j;

                    CreateDashboardControl(ref htc,position);
                    htr.Controls.Add(htc);
                }
                ht.Rows.Add(htr);
            }
            htcResult.Controls.Add(ht);
        }
        catch(Exception ex)
        {
            LogWriter.WriteLog("Error : CreateHTMLTable :"+ ex.Message);
        }
        finally
        {
            ht = null;
            htr = null;
            htc = null;
        }
    }

    private void CreateDashboardControl(ref HtmlTableCell htcResult,string position)
    {
        HtmlTable ht = new HtmlTable();
        HtmlTableRow htr = new HtmlTableRow();
        HtmlTableCell htc = new HtmlTableCell();
        try
        {

            ht.Width = "100%";
            ht.CellSpacing = 0;
            ht.CellPadding = 0;
            ht.Border = 0;

            #region Create Header Button
            //htr = new HtmlTableRow();
            //htc = new HtmlTableCell();
            //htc.Align = "Right";
            //ImageButton btnadd = new ImageButton();
            //btnadd.ImageUrl = "Images/AddRecord.GIF";
            //btnadd.ToolTip = "Click here to add a Dashboard Component";
            //btnadd.ID = "btnAdd_DB_"+position;

            //ImageButton btndel = new ImageButton();
            //btndel.ImageUrl = "images/delete_wizard.GIF";
            //btndel.ToolTip = "Click here to remove this Dashboard Component";
            //btndel.ID = "btnDel_DB_"+position;

            //htc.Controls.Add(btnadd);
            //htc.Controls.Add(btndel);

            //htr.Controls.Add(htc);
            //ht.Controls.Add(htr);

            #endregion

            #region RenderDashboard
            htr = new HtmlTableRow();
            htc = new HtmlTableCell();
            RenderDashboard(ref htc, "select control_seq,control_name from sy_pg_ctr where page_id = '8e9784480fd56593'", "doughnut", null, position);
            htr.Controls.Add(htc);
            ht.Controls.Add(htr);
            #endregion




            htcResult.Controls.Add(ht);

        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error : CreateDashboardConrol:" + ex.Message);
        }
        finally
        {
        }
    }

    private void RenderDashboard(ref HtmlTableCell htcResult,string sql,string ChartType,DataRow drDashboard,string position)
    {
        HtmlTable ht = new HtmlTable();
        HtmlTableRow htr = new HtmlTableRow();
        HtmlTableCell htc = new HtmlTableCell();
        try
        {
            ht.Width = "100%";
            ht.CellPadding = 0;
            ht.CellSpacing = 0;
            ht.Border = 0;
            
            #region Header of Dashboard
            htr = new HtmlTableRow();
            htc = new HtmlTableCell();
            htc.Attributes.Add("class", "Grid_Header");
            Label lblTitle = new Label();
            lblTitle.Text = "This is sample title";
            htc.Controls.Add(lblTitle);
            htr.Controls.Add(htc);
            ht.Controls.Add(htr);
            #endregion

            #region Create the chart
            htr = new HtmlTableRow();
            htc = new HtmlTableCell();
            CreateChart(ref htc, ChartType, sql,position);
            htr.Controls.Add(htc);
            ht.Controls.Add(htr);
            #endregion


            htcResult.Controls.Add(ht);
        }
        catch(Exception ex)
        {
            LogWriter.WriteLog("Error : RenderDashboard :" + ex.Message);
        }
    }

    private void CreateChart(ref HtmlTableCell htcResult,string controlType,string sql,string position)
    {
        HDDatabase HDD = new HDDatabase();
        UltraChart chart1 = new UltraChart();
        
        DataTable dt = new DataTable();
        try
        {
            switch (controlType.ToLower())
            {
                case "piechart":
                    chart1 = new UltraChart();
                    chart1.ChartType = Infragistics.UltraChart.Shared.Styles.ChartType.PieChart3D;
                    chart1.DeploymentScenario.RenderingType = Infragistics.UltraChart.Shared.Styles.RenderingType.Flash;
                    chart1.DeploymentScenario.Scenario = Infragistics.UltraChart.Shared.Styles.ImageDeploymentScenario.Session;
                    chart1.ImagePipePageName = "ImagePipe.aspx";
                    chart1.Transform3D.XRotation = 50;
                    chart1.Visible = true;
                    chart1.Style.Add(HtmlTextWriterStyle.ZIndex,"-4");
                    chart1.Legend.Visible = true;
                    chart1.ID = "uc_pie_"+ position.Replace(",","");
                    dt = HDD.GetDataTable(sql);
                    chart1.DataSource = dt;
                    chart1.DataBind();
                    htcResult.Controls.Add(chart1);
                    break;
                case "doughnut":
                    chart1 = new UltraChart();
                    chart1.ChartType = Infragistics.UltraChart.Shared.Styles.ChartType.DoughnutChart3D;
                    chart1.DeploymentScenario.RenderingType = Infragistics.UltraChart.Shared.Styles.RenderingType.Flash;
                    chart1.DeploymentScenario.Scenario = Infragistics.UltraChart.Shared.Styles.ImageDeploymentScenario.Session;
                    chart1.ImagePipePageName = "ImagePipe.aspx";
                    chart1.Transform3D.XRotation = 50;
                    chart1.Style.Add(HtmlTextWriterStyle.ZIndex, "-4");
                    chart1.Legend.Visible = true;
                    chart1.ID = "uc_pie_"+position.Replace(",","");
                    dt = HDD.GetDataTable(sql);
                    chart1.DataSource = dt;
                    chart1.DataBind();
                    htcResult.Controls.Add(chart1);
                    break;
                default:
                    break;
            }
        }
        catch(Exception ex)
        {
            LogWriter.WriteLog("Error : CreateChart : "+ ex.Message);
        }
        finally
        {
            HDD = null;
        }
        
    }

    private void GetConfigDataSet()
    {
        HDDatabase HDD = new HDDatabase();
        DataTable dt = new DataTable();
        try
        {
            string sql = "select * from sy_acr_mem where acr_id = 'be456d9eb79818ba'";
            dt = HDD.GetDataTable(sql,"Config");
            if (dt != null)
                dsConfig.Tables.Add(dt.Copy());
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error : GetConfigDataSet :" + ex.Message);
        }
        finally
        {
            HDD = null;
            dt = null;
        }
    }

    private void LoadLayoutStyle()
    {
        try
        {
            if(dsConfig!=null)
                if(dsConfig.Tables.Count>0)
                    if (dsConfig.Tables["Config"] != null)
                    {
                        DataTable dt = dsConfig.Tables["Config"];
                        DataRow[] drr = dt.Select("mem_id = 'Layout' and mem_value2 = 'True'","mem_seq");
                        if (drr.Length > 0)
                        {
                            for (int i = 0; i < drr.Length;i++)
                            //foreach (DataRow dr in drr)
                            {
                                ddlLayoutStyle.Items.Add(new ListItem(drr[i]["mem_value1"].ToString(), drr[i]["mem_value3"].ToString().Trim()));
                            }
                        }
                        drr = dt.Select("mem_id = 'WS'", "mem_seq");
                        if (drr.Length > 0)
                        {
                            ddlWidgetSize.Items.Add(new ListItem(""));
                            for (int i = 0; i < drr.Length; i++)
                            {
                                ddlWidgetSize.Items.Add(new ListItem(drr[i]["mem_value1"].ToString(), drr[i]["mem_value2"].ToString()));
                            }
                        }
                    }
        }
        catch(Exception ex)
        {
            LogWriter.WriteLog("Error : LoadLayoutStyle :"+ ex.Message);
        }

    }


    private int GetRowCount(int ItemCount, int ColCount)
    {
        int rowcount = 0;
        try
        {
            if (ItemCount > 0)
            {
                //decimal dec = ItemCount / ColCount;
                double drow = ItemCount / ColCount;
                int inttemp = Convert.ToInt32(drow);
                if (inttemp == 0)
                    inttemp = 1;
                int temp = ItemCount % ColCount;
                if (temp > 0)
                    rowcount = inttemp + 1;
                else
                    rowcount = inttemp;

                if (ItemCount <= ColCount)  //Add only Single Row
                    rowcount = 1;
            }
        }
        catch(Exception ex)
        {
            LogWriter.WriteLog("Error : GetRowCount :"+ ex.Message);
        }
        return rowcount;
    }

    private void LoadAvailableDashboards(ListBox listbox)
    {
        SecurityFilter SF = new SecurityFilter();
        HDDatabase HDD = new HDDatabase();
        DataTable dt = new DataTable();
        try
        {
            string sql = "select af_row_id,name from sy_widgets where active = 1 order by name";
            sql = SF.applysecurity(sql);
            dt = HDD.GetDataTable(sql);
            if(dt!=null)
                foreach (DataRow dr in dt.Rows)
                {
                    listbox.Items.Add(new ListItem(dr["name"].ToString(), dr["af_row_id"].ToString()));
                }
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error : LoadAvailableDashboards :" + ex.Message);
        }
        finally
        {
            
        }
    }


    protected void imgSelectAll_Click(object sender, ImageClickEventArgs e)
    {
        lstAvailableDashboards.Items.Clear();
        lstSelectedDashboards.Items.Clear();
        LoadAvailableDashboards(lstSelectedDashboards);
        GenerateDashboards();
    }
    protected void imgSelect_Click(object sender, ImageClickEventArgs e)
    {
        if (lstAvailableDashboards.Items.Count > 0)
        {
            lstSelectedDashboards.SelectedIndex = -1;
            if (lstAvailableDashboards.SelectedItem != null)
            {
                ListItem item = lstAvailableDashboards.SelectedItem;
                lstAvailableDashboards.Items.Remove(item);
                lstSelectedDashboards.Items.Add(item);
            }
        }
        GenerateDashboards();
    }
    protected void imgUnSelect_Click(object sender, ImageClickEventArgs e)
    {
        if (lstSelectedDashboards.Items.Count > 0)
        {
            lstAvailableDashboards.SelectedIndex = -1;
            if (lstSelectedDashboards.SelectedItem != null)
            {
                ListItem item = lstSelectedDashboards.SelectedItem;
                lstSelectedDashboards.Items.Remove(item);
                lstAvailableDashboards.Items.Add(item);
            }
        }
        GenerateDashboards();
    }
    protected void imgUnSelectAll_Click(object sender, ImageClickEventArgs e)
    {
        lstSelectedDashboards.Items.Clear();
        lstAvailableDashboards.Items.Clear();
        LoadAvailableDashboards(lstAvailableDashboards);
        GenerateDashboards();
    }
    protected void imgUp_Click(object sender, ImageClickEventArgs e)
    {
        int iSelectedIndex = lstSelectedDashboards.SelectedIndex;
        if (iSelectedIndex != -1)
        {
            if (iSelectedIndex != 0)
            {
                ListItem li = lstSelectedDashboards.SelectedItem;
                lstSelectedDashboards.Items.RemoveAt(iSelectedIndex);
                lstSelectedDashboards.Items.Insert(iSelectedIndex - 1, li);
            }
        }
        GenerateDashboards();
    }
    protected void imgdown_Click(object sender, ImageClickEventArgs e)
    {
        int iSelectedIndex = lstSelectedDashboards.SelectedIndex;
        if (iSelectedIndex != -1)
        {
            if (iSelectedIndex != lstSelectedDashboards.Items.Count - 1)
            {
                ListItem li = lstSelectedDashboards.SelectedItem;
                lstSelectedDashboards.Items.RemoveAt(iSelectedIndex);
                lstSelectedDashboards.Items.Insert(iSelectedIndex + 1, li);
            }
        }

        GenerateDashboards();
    }

    private void GenerateDashboards()
    {
        Dashboards DB = new Dashboards();
        DataTable dtWdgSettings = new DataTable(); // Added by 'Imran Gani' on 07-Aug-2014, for Dashboard widget property
        int WdgSettingsCount = 0;
        try
        {
            if (lstSelectedDashboards.Items.Count > 0)
            {
                dtWdgSettings = JsonFunctions.JsonFunctions.JsonToDataTable(hfJsonWdgSettings.Value);
                if (dtWdgSettings != null && dtWdgSettings.Rows.Count > 0)
                    WdgSettingsCount = dtWdgSettings.Select("fullview = 'true' or newsection = 'true'").Length;

                itemcount = lstSelectedDashboards.Items.Count;
                colcount = Convert.ToInt32(ddlLayoutStyle.SelectedValue);
                rowcount = GetRowCount(itemcount, colcount) + WdgSettingsCount;

                ArrayList lstselected = GetDashboardList();

                td_dashboardHeader.Visible = true;
                lblDashboardHeader.Text = HttpUtility.HtmlEncode(txt_title.Text);
                //CreateHTMLTable(ref td_dashboard, rowcount, colcount);
                //CreateHTMLTable(ref td_dashboard, lstselected, rowcount, colcount);
                DB.GenerateDashboards(ref td_dashboard, lstselected, rowcount, colcount, frmObj, dtWdgSettings);
            }
        }
        catch
        {

        }
        finally
        {
            DB = null;
        }
    }
    protected void btnPreview_Click(object sender, EventArgs e)
    {
        GenerateDashboards();
    }

    private ArrayList GetDashboardList()
    {
        ArrayList list = new ArrayList();

        if (lstSelectedDashboards.Items.Count > 0)
        {
            foreach (ListItem lst in lstSelectedDashboards.Items)
            {
                list.Add(lst.Value);
            }
        }
        return list;
    }


    //private void CreateHTMLTable(ref HtmlTableCell htcresult, ArrayList list,int row, int column)
    //{
    //    HDDatabase HDD = new HDDatabase();
    //    Dashboards DB = new Dashboards();
    //    try
    //    {
    //        if (list != null)
    //            if (list.Count > 0)
    //            {
    //                int ilist = list.Count;
    //                int cnt = 1;
    //                HtmlTable ht = new HtmlTable();
    //                ht.Width = "100%";
    //                ht.CellPadding = 0;
    //                ht.CellSpacing = 0;
    //                ht.Border = 0;
    //                HtmlTableRow htr = new HtmlTableRow();
    //                HtmlTableCell htc = new HtmlTableCell();

    //                for (int i = 0; i < row; i++)
    //                {
    //                    htr = new HtmlTableRow();

    //                    for (int j = 0; j < column; j++)
    //                    {
    //                        htc = new HtmlTableCell();
    //                        if (cnt <= ilist)
    //                        {
    //                            string strDBafrowid = list[cnt - 1].ToString();
    //                            DB.GenerateWidgets(strDBafrowid, ref htc, true,frmObj);
    //                            cnt += 1;
    //                        }
    //                        htr.Controls.Add(htc);
    //                    }
    //                    ht.Controls.Add(htr);
    //                }

    //                htcresult.Controls.Add(ht);
    //            }
    //    }
    //    catch (Exception ex)
    //    {
    //        LogWriter.WriteLog("Error : CreateHtmlTable :" + ex.Message);
    //    }
    //    finally
    //    {
    //        HDD = null;
    //        DB = null;
    //    }
    //}

    private void CheckEditOperation()
    {
        try
        {
            if (Request.QueryString["CPY"] != null)
            {
                if (Request.QueryString["CPY"] == "0")
                {
                    btnSave.Visible = true;
                    btnSaveNew.Visible = true;
                    btnUpdate.Visible = false;

                    btnSaveTop.Visible = true;
                    btnSaveNewTop.Visible = true;
                    btnUpdateTop.Visible = false;
                    GetData(ref dseInput);
                    if (!Page.IsPostBack)
                    {
                        SetData(dseInput);
                        GenerateDashboards();
                        HideSelectDashboards();
                    }
                    DynamicDisplayI DDI = new DynamicDisplayI();
                    string sUTC_Offset = DDI.getUserSetting("sy_usr", "time_zone", "sy_timezone", "utc_offset", "timezone_id");
                    DDI = null;
                    DataTable dt = dseInput.Tables["p_dashboard_master"];
                    showDefaultValues(ref dt, this.Page.Form, sUTC_Offset);
                }
            }
            else if (Request.QueryString["PK"] == null)
            {
                btnSave.Visible = true;
                btnSaveNew.Visible = true;
                btnUpdate.Visible = false;

                btnSaveTop.Visible = true;
                btnSaveNewTop.Visible = true;
                btnUpdateTop.Visible = false;
            }
            else
            {
                btnUpdate.Visible = true;
                btnSave.Visible = false;
                btnSaveNew.Visible = false;

                btnUpdateTop.Visible = true;
                btnSaveTop.Visible = false;
                btnSaveNewTop.Visible = false;
                GetData(ref dseInput);
                if (!Page.IsPostBack)
                {
                    SetData(dseInput);
                    GenerateDashboards();
                    HideSelectDashboards();
                }
                DynamicDisplayI DDI = new DynamicDisplayI();
                string sUTC_Offset = DDI.getUserSetting("sy_usr", "time_zone", "sy_timezone", "utc_offset", "timezone_id");
                DDI = null;
                DataTable dt = dseInput.Tables["p_dashboard_master"];
                showDefaultValues(ref dt, this.Page.Form, sUTC_Offset);
            }
        }
        catch
        {
        }
    }

    private bool fillInputData(ref DataSet dseInputInfo)
    {
        bool status = false;
        ScreenReader SR = new ScreenReader();
        try
        {
            SR.CreatePageDataTable(dseInputInfo, dsePageInfo.Tables["Page"], dsePageInfo.Tables["PageCtrl"]);

            GetData(ref dseInput);

            if (dseInputInfo.Tables.Count > 0)
            {
                string strDBMasteraf_row_id = "";
                if (dseInputInfo.Tables["p_dashboard_master"] != null)
                {
                    DataRow drData = dseInputInfo.Tables["p_dashboard_master"].NewRow();

                    drData["name"] = txt_id.Text;
                    drData["header"] = txt_title.Text;
                    drData["description"] = txt_desc.Text;
                    drData["rows"] = GetRowCount(lstSelectedDashboards.Items.Count,Convert.ToInt32(ddlLayoutStyle.SelectedValue));
                    drData["columns"] = Convert.ToInt32(ddlLayoutStyle.SelectedValue);
                    drData["active"] = ChkActive.Checked;
                    drData["owner_id"] = hfowner.Value;
                    if (Request.QueryString["PK"] == null || Request.QueryString["CPY"] != null)
                    {
                        strDBMasteraf_row_id = SR.getHashKey();
                        drData["af_row_id"] = strDBMasteraf_row_id;
                        drData["created_by"] = Session["user_afrowid"].ToString();
                        drData["modified_by"] = Session["user_afrowid"].ToString();
                        drData["created_at"] = DateTime.UtcNow;
                        drData["modified_at"] = DateTime.UtcNow;
                    }
                    else
                    {
                        strDBMasteraf_row_id = hfafrowid.Value;
                        drData["af_row_id"] = hfafrowid.Value;
                        drData["created_by"] = hfcreatedby.Value;
                        drData["modified_by"] = Session["user_afrowid"].ToString();
                        drData["created_at"] = hfcreatedat.Value;
                        drData["modified_at"] = DateTime.UtcNow;
                    }

                    dseInputInfo.Tables["p_dashboard_master"].Rows.Add(drData);


                }
                if (dseInputInfo.Tables["p_dashboard_detail"] != null)
                {
                    if (lstSelectedDashboards.Items.Count > 0)
                    {
                        DataTable dtWdgSettings = JsonFunctions.JsonFunctions.JsonToDataTable(hfJsonWdgSettings.Value); // Added by 'Imran Gani' on 07-Aug-2014, for Dashboard widget property
                        for (int i = 0; i < lstSelectedDashboards.Items.Count; i++)
                        {
                            DataRow drData = dseInputInfo.Tables["p_dashboard_detail"].NewRow();
                            drData["dashboard"] = strDBMasteraf_row_id;
                            drData["widget"] = lstSelectedDashboards.Items[i].Value;
                            drData["sequence"] = i;
                            drData["owner_id"] = hfowner.Value;
                            if (dtWdgSettings != null && dtWdgSettings.Rows.Count > 0)
                            {
                                DataRow[] drWdgSettings = dtWdgSettings.Select("widget = '" + lstSelectedDashboards.Items[i].Value + "'");
                                if (drWdgSettings.Length > 0)
                                {
                                    drData["is_fullview"] = drWdgSettings[0]["fullview"];
                                    drData["is_newsection"] = drWdgSettings[0]["newsection"];
                                    drData["widget_size"] = drWdgSettings[0]["widget_size"];
                                }
                            }
                            if (Request.QueryString["PK"] == null || Request.QueryString["CPY"] != null)
                            {
                                drData["af_row_id"] = SR.getHashKey();
                                drData["created_by"] = Session["user_afrowid"].ToString();
                                drData["modified_by"] = Session["user_afrowid"].ToString();
                                drData["created_at"] = DateTime.UtcNow;
                                drData["modified_at"] = DateTime.UtcNow;
                            }
                            else
                            {
                                if (dseInput.Tables["p_dashboard_detail"] != null)
                                {

                                    DataRow[] dr = dseInput.Tables["p_dashboard_detail"].Select("dashboard='"+Request.QueryString["PK"]+"' and widget = '"+lstSelectedDashboards.Items[i].Value+"'");
                                    if (dr.Length > 0)
                                        drData["af_row_id"] = dr[0]["af_row_id"].ToString();
                                    else
                                        drData["af_row_id"] = SR.getHashKey();

                                    drData["created_by"] = hfcreatedby.Value;
                                    drData["modified_by"] = Session["user_afrowid"].ToString();
                                    drData["created_at"] = hfcreatedat.Value;
                                    drData["modified_at"] = DateTime.UtcNow;
                                }
                            }

                            dseInputInfo.Tables["p_dashboard_detail"].Rows.Add(drData);

                        }
                    }
                }
                status = true;
            }
        }
        catch(Exception ex)
        {
            LogWriter.WriteLog("Error : fillInputData :"+ ex.Message);
        }
        finally
        {
            SR = null;
        }
        return status;
    }

    private void GetData(ref DataSet dseInput)
    {
        HDDatabase HDD = new HDDatabase();
        try
        {
            if (Request.QueryString["PK"] != null)
            {
                string sql = "select * from sy_dashboard_master where af_row_id = '"+Request.QueryString["PK"]+"'";
                DataTable dt = HDD.GetDataTable(sql,"p_dashboard_master");
                if (dt != null)
                    dseInput.Tables.Add(dt.Copy());
                sql = "select * from sy_dashboard_detail where dashboard = '"+Request.QueryString["PK"]+"' order by sequence";
                dt = HDD.GetDataTable(sql, "p_dashboard_detail");
                if (dt != null)
                    dseInput.Tables.Add(dt.Copy());

                //function added by bala on 17-Nov-2011 for IPP Tech check 
                //CommonFunctions.decodeData(dseInputInfo);
            }
        }
        catch(Exception ex)
        {
            LogWriter.WriteLog("Error : GetDashboardDetail :"+ ex.Message);
        }
        finally
        {
            HDD = null;
        }
    }

    private void SetData(DataSet dsInput)
    {
        HDDatabase HDD = new HDDatabase();
        System.Text.StringBuilder sbWidgetSettings = new System.Text.StringBuilder(); // Added by 'Imran Gani' on 07-Aug-2014, for Dashboard widget property
        try
        {
            if(dseInput!=null)
                if (dseInput.Tables.Count > 0)
                {
                    //function added by Sampath on 17-Nov-2011 for IPP Tech check 
                    //CommonFunctions.decodeData(dseInput);
                    if (dseInput.Tables["p_dashboard_master"] != null)
                    {
                        DataTable dt = dseInput.Tables["p_dashboard_master"];
                        if (dt.Rows.Count > 0)
                        {
                            DataRow drData = dt.Rows[0];

                            txt_id.Text = drData["name"].ToString();
                            txt_desc.Text = drData["description"].ToString();
                            txt_title.Text = drData["header"].ToString();
                            ddlLayoutStyle.SelectedValue = drData["columns"].ToString();
                            ChkActive.Checked = drData["active"].ToString() != "" ? Convert.ToBoolean(drData["active"].ToString()) : false;
                            hfafrowid.Value = drData["af_row_id"].ToString();
                            hfcreatedby.Value = drData["created_by"].ToString();
                            hfcreatedat.Value = drData["created_at"].ToString();
                            hfowner.Value = drData["owner_id"].ToString();
                            txt_Owner.Text = getValueToStore("sy_usr", "user_id", "af_row_id", drData["owner_id"].ToString());
                        }
                    }
                    if (dseInput.Tables["p_dashboard_detail"] != null)
                    {
                        DataTable dt = dsInput.Tables["p_dashboard_detail"];
                        if (dt.Rows.Count > 0)
                        {
                            string widgets = "";
                            ArrayList list = new ArrayList();
                            foreach(DataRow dr in dt.Rows)
                            {
                                list.Add(dr["widget"].ToString());
                                widgets += "'"+dr["widget"].ToString() + "',";
                            }
                            widgets = widgets.TrimEnd(',');
                            DataTable dtWidgets = HDD.GetDataTable("select name,af_row_id from sy_widgets where af_row_id in ("+widgets+")");
                            if(dtWidgets!=null)
                            {
                                lstSelectedDashboards.Items.Clear();
                                foreach (DataRow dr in dt.Rows)
                                {
                                    DataRow[] drr = dtWidgets.Select("af_row_id= '" + dr["widget"].ToString() + "'");
                                    if (drr.Length > 0)
                                    {
                                        lstSelectedDashboards.Items.Add(new ListItem(drr[0]["name"].ToString(), dr["widget"].ToString()));
                                        sbWidgetSettings.Append("{" + "\"widget\" : \"" + dr["widget"].ToString() + "\", \"fullview\" : \"" + dr["is_fullview"].ToString() + "\", \"newsection\" : \"" + dr["is_newsection"].ToString() + "\", \"widget_size\" : \"" + dr["widget_size"].ToString() + "\"},");
                                    }
                                }
                            }
                            if (sbWidgetSettings.ToString() != "")
                            {
                                if (sbWidgetSettings.ToString().EndsWith(","))
                                    sbWidgetSettings.Remove(sbWidgetSettings.ToString().LastIndexOf(","), 1);
                                hfJsonWdgSettings.Value = "{\"jsondata\":[" + sbWidgetSettings.ToString() + "]}";
                            }
                            sbWidgetSettings = null;

                            foreach (string item in list)
                            {
                                if (lstAvailableDashboards.Items.FindByValue(item) != null)
                                {
                                    lstAvailableDashboards.Items.Remove(lstAvailableDashboards.Items.FindByValue(item));
                                }
                            }
                            
                        }
                    }
                }
        }
        catch(Exception ex)
        {
            LogWriter.WriteLog("Error : SetData :"+ ex.Message);
        }
    }
    private string wrapItAsMessage(string msg, bool isError)
    {
        return "<div class=\"" + (isError == true ? "mbErrorMessage" : "mbMessage") + "\">" + msg + "</div>";
    }
    private bool SaveData()
    {
        bool bReturn = false;
        Master objMaster = new Master();
        try
        {
            if(ValidateDashboards())
            if (validateOwnerID())
                if (fillInputData(ref dseInputInfo))
                {
                    //if (!validateOwnerid())
                    // {
                    //  return false;
                    //}
                    //function added by Sampath on 17-Nov-2011 for IPP Tech check 
                    //CommonFunctions.encodeData(dseInputInfo);
                    bReturn = objMaster.ProcessOperation(dsePageInfo, dseInputInfo, "INSERT");
                    if (!bReturn)
                    {
                        lblmessage.Text = wrapItAsMessage(objMaster.ErrorMessage,true);
                        strErrorMessage = objMaster.ErrorMessage;
                    }

                    //function added by bala on 17-Nov-2011 for IPP Tech check 
                    //CommonFunctions.encodeData(dseInputInfo);
                }
            
            
        }
        catch(Exception ex)
        {
            LogWriter.WriteLog("Error : SaveData : "+ ex.Message);
        }
        return bReturn;
    }
    private bool UpdateData()
    {
        bool bReturn = false;
        Master objMaster = new Master();
        try
        {
            if(ValidateDashboards())
            if (validateOwnerID())
            {
                if (fillInputData(ref dseInputInfo))
                {
                    if (PerformUpdate(dsePageInfo, dseInputInfo))
                    {
                        //function added by bala on 18-Nov-2011 for IPP Tech check 
                        //CommonFunctions.encodeData(dseInputInfo);
                        bReturn = objMaster.ProcessOperation(dsePageInfo, dseInputInfo, "INSERT");
                    }

                    if (!bReturn)
                    {

                        lblmessage.Text = wrapItAsMessage(objMaster.ErrorMessage,true);
                        strErrorMessage = objMaster.ErrorMessage;
                    }
                }
            }
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error : SaveData : " + ex.Message);
        }
        return bReturn;
    }
    protected void btnSaveTop_Click(object sender, EventArgs e)
    {
        if (SaveData())
        {
            string urlNavigate = Navigator.getURL(Request.Url.AbsoluteUri.ToString());
            Response.Redirect(urlNavigate);
        }
        else
        {
            if (strErrorMessage.Trim() != "")
                lblmessage.Text = wrapItAsMessage("<img src=\"Images/error.gif\" alt=\"Error\"></img>&nbsp;" + "Data Insert not successful. " + strErrorMessage,true);
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (SaveData())
        {
            string urlNavigate = Navigator.getURL(Request.Url.AbsoluteUri.ToString());
            Response.Redirect(urlNavigate);
        }
        else
        {
            if (strErrorMessage.Trim() != "")
                lblmessage.Text = wrapItAsMessage("<img src=\"Images/error.gif\" alt=\"Error\"></img>&nbsp;" + "Data Insert not successful. " + strErrorMessage,true);
        }
    }
    protected void btnSaveNew_Click(object sender, EventArgs e)
    {
        if (SaveData())
        {
            string urlNavigate = HttpContext.Current.Request.Url.AbsolutePath + "?pgs_id=" + HttpContext.Current.Request.QueryString["pgs_id"] + "&mn=" + HttpContext.Current.Request.QueryString["mn"];
            Response.Redirect(urlNavigate);
        }
        else
        {
            if (strErrorMessage.Trim() != "")
                lblmessage.Text = wrapItAsMessage("<img src=\"Images/error.gif\" alt=\"Error\"></img>&nbsp;" + "Data Insert not successful. " + strErrorMessage,true);
        }
    }
    protected void btnSaveNewTop_Click(object sender, EventArgs e)
    {
        if (SaveData())
        {
            string urlNavigate = HttpContext.Current.Request.Url.AbsolutePath + "?pgs_id=" + HttpContext.Current.Request.QueryString["pgs_id"] + "&mn=" + HttpContext.Current.Request.QueryString["mn"];
            Response.Redirect(urlNavigate);
        }
        else
        {
            if (strErrorMessage.Trim() != "")
                lblmessage.Text = wrapItAsMessage("<img src=\"Images/error.gif\" alt=\"Error\"></img>&nbsp;" + "Data Insert not successful. " + strErrorMessage,true);
        }
    }
    protected void btnUpdateTop_Click(object sender, EventArgs e)
    {
        if (UpdateData())
        {
            string urlNavigate = Navigator.getURL(Request.Url.ToString());
            Response.Redirect(urlNavigate);
        }
        else
        {
            if (strErrorMessage.Trim() != "")
                lblmessage.Text = wrapItAsMessage("<img src=\"Images/error.gif\" alt=\"Error\"></img>&nbsp;" + "Data Update not successful. " + strErrorMessage,true);
        }
    }
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        if (UpdateData())
        {
            string urlNavigate = Navigator.getURL(Request.Url.ToString());
            Response.Redirect(urlNavigate);
        }
        else
        {
            if (strErrorMessage.Trim() != "")
                lblmessage.Text = wrapItAsMessage("<img src=\"Images/error.gif\" alt=\"Error\"></img>&nbsp;" + "Data Update not successful. " + strErrorMessage,true);
        }
    }
    protected void btnReset_Click(object sender, EventArgs e)
    {
        Reset();
    }
    protected void btnResetTop_Click(object sender, EventArgs e)
    {
        Reset();
    }

    private String getValueToStore(String TableName, String ColumnName1, String ColumnName2, String Value)
    {
        String sReturn = "";
        HDDatabase HDD = null;
        if (Value != "")
        {
            HDD = new HDDatabase();
            sReturn = HDD.GetColumnValue("Select " + ColumnName1 + " from " + TableName + " where " + ColumnName2 + "='" + Value.Replace("'", "''") + "'");
            HDD = null;
        }
        return sReturn;
    }
    private void HideSelectDashboards()
    {
        CollapsiblePanelExtender1.Collapsed = true;
    }

    private void isViewMode()
    {
        try
        {
            if (Request.QueryString["VMODE"] != null)
            {
                if (Request.QueryString["VMODE"].ToString() == "1")
                {
                    //DynamicDisplayI DDI = new DynamicDisplayI();
                    //DDI.disableControls(this);

                    imgowner.Visible = false;
                    td_space.Visible = false;

                    pnlSelectDashboards.Visible = false;
                    pnlHeader.Visible = false;
                    pnlButtonsTop.Visible = false;
                    pnlButtons.Visible = false;
                    ShowGoToListPageLink();
                    LoadDashboardToolTip(txt_desc.Text);
                }
            }
        }
        catch
        {
        }
    }

    private void ShowGoToListPageLink()
    {
        try
        {
            lnkDashboardList.Visible = true;
            lnkDashboardList.HRef = "DisplayGrid.aspx?pgs_id="+Request.QueryString["pgs_id"]+"&mn="+Request.QueryString["mn"]+"&DBD=1";
        }
        catch
        {
        }
    }

    private bool validateOwnerID()
    {
        bool status = true;
        if (txt_Owner.Text.Trim() != "")
        {
            string Owner = getValueToStore("sy_usr", "af_row_id", "user_id", txt_Owner.Text.Trim());
            if (Owner == "")
            {
                strErrorMessage = "Invalid data for Owner : " + txt_Owner.Text;
                lblmessage.Text = wrapItAsMessage("Invalid data for Owner : " + txt_Owner.Text,true);
                status = false;
                GenerateDashboards();
            }
            else
            {
                hfowner.Value = Owner;
                status = true;
            }
        }
        else
        {
            hfowner.Value = "";
        }
        return status;

    }
    private void Reset()
    {
        string url = Request.Url.ToString();
        Response.Redirect(url);
    }

    private void checkforButtonClick()
    {
        try
        {
            if (hfEventTriggered.Value.Trim() == "1")
                GenerateDashboards();
        }
        catch(Exception ex)
        {
            LogWriter.WriteLog("Error : checkforButtonClick:"+ex.Message);
        }
    }

    private bool PerformUpdate(DataSet dsePageInfo,DataSet dseInput)
    {
        HDDatabase HDD = new HDDatabase();
        bool status = false;
        try
        {
            if (dseInput.Tables["p_dashboard_master"] != null)
            {
                string strid = dseInput.Tables["p_dashboard_master"].Rows[0]["af_row_id"].ToString();

                string sql = "delete from sy_dashboard_detail where dashboard = '" + strid + "';delete from sy_dashboard_master where af_row_id = '"+strid+"'";

                HDD.ExecuteCmdObj(new SqlCommand(sql));

                //status = objMaster.ProcessOperation(dsePageInfo, dseInputInfo, "INSERT");
                status = true;

            }
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error : PerformUpdate :" + ex.Message);
        }
        finally
        {
            HDD = null;
        }
        return status;
    }

    private bool ValidateDashboards()
    {
        bool status = true;
        try
        {
            if (lstSelectedDashboards.Items.Count < 1)
            {
                strErrorMessage = "Please select atleast one widget in the selected list";
                status = false;
            }
        }
        catch(Exception ex)
        {
            LogWriter.WriteLog("Error : ValidateDashboards :"+ ex.Message);
        }
        return status;
    }
    private void setHeaderText()
    {
            if (Request.QueryString["PK"] != null)
            {
                lblheader.Text = "Dashboard Designer - Edit";
            }
            else
            {
                lblheader.Text = "Dashboard Designer - Add";
            }
            if (Request.QueryString["CPY"] != null)
            {
                lblheader.Text = "Dashboard Designer - Copy";
            }
            if (Request.QueryString["Vmode"] != null)
            {
                lblheader.Text = "Dashboard Designer - View";
            }

            if (drPageInfo != null)
                AddPageToolTip(drPageInfo, ref lblheader);

            getpageicons(); // Added by 'Imran Gani' on 05-Dec-2012, to get header icon.
    }

    private void getpageicons() // Added by 'Imran Gani' on 05-Dec-2012, to get header icon.
    {
        PageIcons icons = new PageIcons();
        try
        {
            lblheader.Text = "&nbsp;" + icons.geticontextfrompageset(Request.QueryString["pgs_id"].ToString(), 2) + "&nbsp;" + lblheader.Text;
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error :getpageicons() " + ex.Message);
            lblheader.Text = "<img src=" + PageIcons.strdefaulticon.ToString() + "></img>&nbsp;" + lblheader.Text;
        }
        finally
        {
            icons = null;
        }
    }

    private void AddPageToolTip(DataRow drpage, ref Label lblHeader)
    {
        if (drpage != null)
        {
            //if(!Page.IsPostBack)
            lblHeader.Text = lblHeader.Text + getTootipIcon(drpage);
            Literal lit = new Literal();
            lit.Text = getTooltipContent(drpage);
            td_Page_ToopTip.Controls.Add(lit);
        }
    }
    private void LoadDashboardToolTip(string tooltip)
    {
        //function added by bala on 18-Nov-2011 for IPP Tech check 
        lblDashboardHeader.Text = lblDashboardHeader.Text + getTootipIcon(tooltip);
        Literal lit = new Literal();
        lit.Text = getTooltipContent(tooltip);
        td_db_page_tooltip_view.Controls.Add(lit);
        
    }
    private string getTootipIcon(DataRow droPage)
    {
        try
        {
            if (!droPage.Table.Columns.Contains("page_desc")) return "";
            if (droPage["page_desc"].ToString().Trim() == "") return "";
            return "&nbsp;<img id=\"page_tooltip_img\" style=\"cursor:pointer;\" src=\"Images/collapse3.gif\" onClick=\"javascript:showHideTooltipDIV();\" border=\"0\"></img>";
        }
        catch (Exception e)
        {
            return "";
        }
    }
    private string getTootipIcon(string tooltip)
    {
        try
        {
            if (tooltip.Trim() == "")
                return "";
            return "&nbsp;<img id=\"page_tooltip_img_db\" style=\"cursor:pointer;\" src=\"Images/collapse3.gif\" onClick=\"javascript:showHideTooltipDIVDashboard('page_tooltip_img_db');\" border=\"0\"></img>";
        }
        catch (Exception e)
        {
            return "";
        }
    }

    private string getTooltipContent(DataRow droPage)
    {
        if (!droPage.Table.Columns.Contains("page_desc")) return "";
        if (droPage["page_desc"].ToString().Trim() == "") return "";
        //string ret = "";
        //ret = "<div id=\"page_tooltip_div\" style=\"border-bottom:solid 1px #000000;\">";
        //ret += "<table border=\"0\" cellpadding=\"5\" cellspacing=\"0\" width=\"100%\"><tr><td width=\"10%\" valign=\"center\" align=\"center\"><img src=\"Images/info.gif\" border=\"0\"></img></td><td width=\"80%\" class=\"controlFont\">";
        //ret += droPage["page_desc"].ToString();
        //ret += "</td></tr></table>";
        //ret +="</div>";
        return getContent(HttpContext.Current.Server.MapPath("") + @"\scripts\pagetooltipcontent.txt").Replace("<<content>>", CommonFunctions.SafeEncode(droPage["page_desc"].ToString()));
    }

    private string getTooltipContent(string tooltip)
    {
        if (tooltip.Trim() == "")
            return "";
        return getContent(HttpContext.Current.Server.MapPath("") + @"\scripts\pagetooltipcontent.txt").Replace("<<content>>", CommonFunctions.SafeEncode(tooltip));
    }

    private string getContent(string fileName)
    {
        try
        {
            if (!File.Exists(fileName))
                return "";
            string temp = "";
            StreamReader sr = new StreamReader(fileName);
            temp = sr.ReadToEnd();
            sr.Close();
            sr = null;
            return temp;
        }
        catch (Exception e)
        {
            return "";
        }
    }
    protected void ddlLayoutStyle_SelectedIndexChanged(object sender, EventArgs e)
    {
        GenerateDashboards();
    }

    private void showDefaultValues(ref DataTable dtData, HtmlForm frmObj, string sUTC_Offset)//implemented by sanal on 08 April 2008
    {
        if (HttpContext.Current.Request.QueryString["CPY"] != null)
        {
            if (HttpContext.Current.Request.QueryString["CPY"] == "0")
            {
                return;
            }
        }
        if (dtData == null) return;
        if (dtData.Rows.Count < 1) return;
        if (!dtData.Columns.Contains("created_by")) return;
        if (!dtData.Columns.Contains("modified_at")) return;
        DynamicDisplayI DDI = new DynamicDisplayI();
        try
        {
            HtmlTable ht = new HtmlTable();
            HtmlTableRow htr = new HtmlTableRow();

            //HDDatabase hdd = new HDDatabase();
            //string userDisplayField = hdd.GetColumnValue("sy_acr_mem", "mem_id", "af_row_id='30583eb791cb7d5b'");
            //userDisplayField = userDisplayField.Trim().Length==0 ? "user_id" : userDisplayField;
            //string userName = hdd.GetColumnValue("sy_usr", userDisplayField, "af_row_id='" + dtData.Rows[0]["created_by"].ToString() + "'");
            string userName = getUserName(dtData.Rows[0]["created_by"].ToString()); //hdd.GetColumnValue("sy_usr", userDisplayField, "af_row_id='" + dtData.Rows[0]["created_by"].ToString() + "'");
            //hdd = null;


            HtmlTableCell htc = new HtmlTableCell();
            if (userName.Trim().Length > 0)
            {
                //htc.Controls.Add(new LiteralControl("<b>Owner:</b>&nbsp;" + userName));
                // Added by srivatsan on June 15 2009 for owner id field
                htc.Controls.Add(new LiteralControl("<b>Created By:</b>&nbsp;" + userName));
                htc.Width = "50%";
                htr.Cells.Add(htc);
                //ht.Rows.Add(htr);
            }
            userName = null;

            htc = new HtmlTableCell();
            //DateTime dt = DateTime.Parse(dtData.Rows[0]["modified_at"].ToString());
            //string dat = DDI.getUsersDT(dtData.Rows[0]["modified_at"].ToString(), sUTC_Offset);
            Localization ll = new Localization();
            //htc.Controls.Add(new LiteralControl("<b>Last updated at:</b>&nbsp;" + dt.ToLocalTime().ToString("dd-MMM-yyyy hh:mm:ss tt")));
            htc.Controls.Add(new LiteralControl("<b>Last updated at:</b>&nbsp;" + ll.getDateTime4TimeZone(dtData.Rows[0]["modified_at"].ToString(), sUTC_Offset, false, true)));
            ll = null;
            htc.Width = "50%";
            htc.Align = "center";
            htr.Cells.Add(htc);

            ht.Rows.Add(htr);
            htr.Attributes.Add("Class", "Dynamic_HtmlTableCell");

            HtmlTableCell htcObj = (HtmlTableCell)DDI.FindControl(frmObj.Controls, "tdcDefaultFields");
            ht.Width = "100%";
            ht.Border = 0;
            ht.CellPadding = 0;
            ht.CellSpacing = 0;
            ht.EnableViewState = false;
            htcObj.Controls.Add(ht);
        }
        catch (Exception e)
        {
            LogWriter.WriteLog("Error in showDefaultValues function. Error: " + e.Message);
        }
        finally
        {
            DDI = null;
        }
    }
    private string getUserName(string rowid)
    {
        HDDatabase hdd = new HDDatabase();
        DataTable dt = new DataTable();
        string ret = "";
        try
        {
            string userDisplayField = hdd.GetColumnValue("sy_acr_mem", "mem_id", "af_row_id='30583eb791cb7d5b'");
            userDisplayField = userDisplayField.Trim().Length == 0 ? "user_id" : userDisplayField;
            dt = hdd.GetDataTable("select " + userDisplayField + " from sy_usr where af_row_id='" + rowid + "'");
            if (dt != null)
                if (dt.Rows.Count > 0)
                    ret = dt.Rows[0][0].ToString();
        }
        catch (Exception e)
        {
            LogWriter.WriteLog("Error in getUserName : " + e.ToString());
        }
        finally
        {
            hdd = null;
            dt = null;
        }
        return ret;
    }
}
